<?php 
$thoigian = array();
$j=0;
$thoidiem = "Sáng";
for($i =6; $i <=22; $i++){
	if($i>=18){
		$thoidiem = "Tối";
	}else if($i>=13){
		$thoidiem = "Chiều";
	}else if($i>=11){
		$thoidiem = "Trưa";
	}
	$thoigian[$j] = array('value'=> $j, 'label' => $i.":00", 'group'=>$thoidiem);
	$j++;
	$thoigian[$j] = array('value'=> $j, 'label' => $i.":30", 'group'=>$thoidiem);
	$j++;
}

?>

<div class='form'>
<?php $this->beginWidget('bootstrap.widgets.TbModal', array('id' => 'datsan-modal', )); ?>
    <div class="modal-header">
        <a class="close" data-dismiss="modal">&times;</a>
        <h3>Đặt sân</h3>
    </div>


<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	'id'=>'datsan-form',
	'enableAjaxValidation'=>false,
)); ?>
    <div class="modal-body">
	<div class="row">
	<?php echo $form->labelEx($model,'ngaydat'); 		
		   	 $this->widget('zii.widgets.jui.CJuiDatePicker',array(
		        'model'=>$model, //Model object
		        'attribute'=>'ngaydat', //attribute name
		        'options'=>array(), // jquery plugin options
		    	 'language' => 'vi'
		    ));
		?>
		<?php echo $form->error($model,'ngaydat'); ?>
		<?php echo $form->hiddenField($model,'idsan'); ?>
	</div>

	<div class="row">
		<?php echo $form->dropDownListRow($model,'giovao',CHtml::listData($thoigian,'value','label', 'group')); ?>
	</div>

	<div class="row">
		<?php echo $form->dropDownListRow($model,'giora',CHtml::listData($thoigian,'value','label', 'group')); ?>
	</div>
	</div>
<div class="modal-footer">
	<div class="row buttons">
		 <?php echo CHtml::ajaxSubmitButton('Đặt sân',CHtml::normalizeUrl(array('datsan/createajax')),
             array(
                 'dataType'=>'json',
                 'type'=>'post',
                 'success'=>'function(data) { 
                    if(data.status=="success"){
                     $("#formResult").html("Đăng ký thành công");
                    }
                     else{
                     $("#formResult").html("<span style=\"color:red;\">"+data.message+"</span>");
                    $("#Datsan_giora_em_").text(data.Datsan_giora);
	                  /*  $.each(data, function(key, val) {
		                    $("#datsan-form #"+key+"_em_").text(val);                                                    
		                    $("#datsan-form #"+key+"_em_").show();
	                    });*/
                    }       
                }',                    
                 'beforeSend'=>'function(){        
                  }'
                 ),array('id'=>'mybtn','class'=>'btn btn-success')); ?>
                 
                 <span id='formResult' style='color: green; font-weight: bold; float: left;'></span>
	</div>

<?php $this->endWidget(); ?>
<?php $this->endWidget(); ?>



</div>

</div>
